package com.godyao.mall.goods.controller.admin;


import com.godyao.mall.core.model.ResultMsg;
import com.godyao.mall.core.model.goods.Goods;
import com.godyao.mall.goods.service.IGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author godyao
 * @date 2022/3/31
 */
@Api(value = "商品相关接口-后台")
@RequestMapping(value = "/admin")
@RestController
@RequiredArgsConstructor
public class GoodsAdminController {
    private final IGoodsService goodsService;

    @ApiOperation("添加商品")
    @PostMapping("/goods")
    public ResultMsg<Goods> addGoods(@RequestBody Goods goods) {
        return ResultMsg.resultSuccess(goodsService.save(goods));
    }

    @ApiOperation("更新商品")
    @PutMapping("/goods")
    public ResultMsg<Goods> updateGoods(@RequestBody Goods goods) {
        return ResultMsg.resultSuccess(goodsService.save(goods));
    }

    @ApiOperation("删除商品")
    @DeleteMapping("/goods/{goodsId}")
    public ResultMsg<Goods> updateGoods(@PathVariable Long goodsId) {
        goodsService.delGoods(goodsId);
        return ResultMsg.resultSuccess();
    }
}
